<?php
//更改图片
$id=$_REQUEST["id"];
$url="./resource/news/news".$id;//文件夹位置
if(is_uploaded_file($_FILES['uppicture']['tmp_name'])){
    $picurl=$url."/news".$id.".jpeg";
    unlink($picurl);//删除原图片
    if(move_uploaded_file($_FILES['uppicture']['tmp_name'],$picurl)){
        //图片上传成功
    }
}



//更改库中的title和time
$time =date("Y-m-d H:i:s");
$title=$_POST['title'];
$game=$_POST["select"];
$conn=new mysqli("localhost","root","123456","htmlkeshe");
$conn->query("set names utf8");
$sql1="UPDATE news SET title='".$title."' WHERE newsId=".$id.";";
$result1=$conn->query($sql1) or die(mysqli_error($conn));
$sql2="UPDATE news SET newsTime='".$time."' WHERE newsId=".$id.";";
$result2=$conn->query($sql2) or die(mysqli_error($conn));
$sql3="UPDATE news SET whichGame='".$game."' WHERE newsId=".$id.";";
$result3=$conn->query($sql3) or die(mysqli_error($conn));

//更改txt文档内容
$sql="SELECT * FROM news WHERE newsId=".$id.";";
$result=$conn->query($sql) or die(mysqli_error($conn));
if($result->num_rows>0) {
    while ($row = $result->fetch_assoc()) {
        $txturl=$row['newsContent'];
    }
}
unlink($txturl);//删除原文档
$text=$_POST['news'];
$txturl=$url."/".$_POST['title'].'.txt';
$myfile = fopen($txturl, "w");
fwrite($myfile, $text);
fclose($myfile);

$conn->close();
header('Refresh: 0; url=Personal.php');?>
<script>
    alert("修改成功!")
</script>
